package com.thero.core.chess;

/**
 * Created by wusk on 2017/11/27.
 */
public class Point {
    private boolean isValid;
    private int key;
    private Piece piece;
    private int[] horizontal;
    private int[] vertical;

    public Point(int key, int[] horizontal, int[] vertical){
        this.key = key;
        this.horizontal = horizontal;
        this.vertical = vertical;
        this.isValid = true;
    }

    public Point(int key, int h1, int h2, int h3, int v1, int v2, int v3 ){
        this.key = key;
        this.horizontal = new int[3];
        this.horizontal[0] = h1;
        this.horizontal[1] = h2;
        this.horizontal[2] = h3;
        this.vertical = new int[3];
        this.vertical[0] = v1;
        this.vertical[1] = v2;
        this.vertical[2] = v3;
        this.isValid = true;
    }

    public boolean isValid(){
        return this.isValid;
    }

    public void valid(){
        this.isValid = true;
    }

    public void invalid(){
        this.isValid = false;
    }

    public int key(){
        return this.key;
    }

    public Piece getPiece(){
        return this.piece;
    }

    public void setPiece(Piece piece){
        this.piece = piece;
    }

    public void removePiece(){
        this.piece = null;
    }

    public boolean isEmpty(){
        if(null == this.piece){
            return true;
        }
        return false;
    }

    public boolean isFilled(){
        if(null == this.piece){
            return false;
        }
        return true;
    }

    public Piece pickup(){
        Piece piece = this.piece;
        this.piece = null;
        return piece;
    }

    /**
     * 判断两个棋子位置是否相邻
     * @param another 被判定的棋子key
     * @return 判定结果
     */
    public boolean isAdjacent(int another){
        if(0 == another){
            return false;
        }
        for(int key: horizontal){
            if(another == key){
                return true;
            }
        }
        for(int key: vertical){
            if(another == key){
                return true;
            }
        }
        return false;
    }

    public int[] horizontal(){
        return this.horizontal;
    }

    public int[] vertical(){
        return this.vertical;
    }
}
